package com.kantboot.project.security.service.impl;

import com.kantboot.project.security.entity.SysSetting;
import com.kantboot.project.security.repository.SysSettingRepository;
import com.kantboot.project.security.service.ISysSettingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysSettingServiceImpl implements ISysSettingService {

    @Resource
    SysSettingRepository repository;

    @Override
    public void setRoleIdByUserJoin(Long roleId) {
        SysSetting sysSetting = getSettingBySet();
        sysSetting.setRoleIdByUserJoin(roleId);
        repository.save(sysSetting);
    }

    @Override
    public void setAuthAppletWechatIdByUserJoin(Long authAppletWechatId) {
        SysSetting sysSetting = getSettingBySet();
        sysSetting.setAppletWechatIdByUserJoin(authAppletWechatId);
        repository.save(sysSetting);
    }

    @Override
    public void setAuthPayNotifyId(Long authPayNotifyId) {
        SysSetting sysSetting = getSettingBySet();
        sysSetting.setAuthPayNotifyId(authPayNotifyId);
        repository.save(sysSetting);
    }

    @Override
    public SysSetting getSetting() {
        return repository.findById(1l).get();
    }

    public SysSetting getSettingBySet() {
        synchronized (this.getClass()){
            return repository.findById(1l).get();
        }
    }

}
